<?php
namespace app\facescore\admin;
use app\admin\controller\Admin;
use app\facescore\model\FacescoreBanner as TypeModel;
use think\Db;

class Content extends Admin
{
    //用户发布内容展示
    public function index($q = '',$is_apply = '')
    {
        $map = [];
        if ($q) {
            $map['m.nick'] = ['like', '%'.$q.'%'];
        }
        if($is_apply) {
            $map['r.is_apply'] = ['like', '%'.$is_apply.'%'];
        }
        $map['r.is_del'] = 0;
        $data_list = Db::name('facescore_content r')->join('admin_member m','m.id = r.uid')->field('r.*')->where($map)->order('r.create_time desc')->paginate(10, false, ['query' => input('get.')]);
        $pages = $data_list->render();
        $this->assign('data_list', $data_list);
        $this->assign('pages', $pages);
        $this->assign('is_apply', $is_apply);
        return $this->fetch();
    }
    /**
     * 展示图集 -- 用户发布
     */
    public function showimgs($content_id){
        $data_list = Db::name('facescore_imgs')->where('content_id',$content_id)->order('id asc')->select();
        $this->assign('data_list', $data_list);
        $this->view->engine->layout('newLayout');
        $this->view->engine->layout(false);
        return $this->fetch();
    }

    /**
     * 打赏记录
     */
    public function reward($q = '',$content_id = ''){
        $map = [];
        if ($q) {
            $map['m.nick'] = ['like', '%'.$q.'%'];
        }
        if($content_id) {
            $map['r.content_id'] = $content_id;
        }
        $map['r.status'] = 1;
        $data_list = Db::name('facescore_reward r')->join('admin_member m','m.id = r.uid')->field('r.*,m.nick')->where($map)->order('r.id desc')->paginate(10, false, ['query' => input('get.')]);
        $pages = $data_list->render();
        $this->assign('data_list', $data_list);
        $this->assign('pages', $pages);
        return $this->fetch();
    }

    /**
     * 审核
     * @param string $val 审核操作结果
     * @param string $ids 内容ID
     */
    public function audit($val = '',$ids = ''){
        Db::name('facescore_content')->where(['id' => $ids])->update(['audit' => $val]);
        return json(['msg'=>'操作成功']);
    }

    /**
     * 状态修改
     * 设置推荐时会自动修改审核状态为审核通过
     * @param string $val
     * @param string $ids
     * @return \think\response\Json
     */
    public function status($val = '',$ids = ''){
        $data = [];
        $data['status'] = $val;
        if($val == 1) {
            $data['audit'] = 1;
        }
        Db::name('facescore_content')->where(['id' => $ids])->update($data);
        return json(['msg'=>'操作成功']);
    }

    /**
     * 推荐管理
     * @param string $q
     * @param string $is_apply
     * @return string
     */
    public function recommend($q = '',$is_apply = '')
    {
        $map = [];
        if ($q) {
            $map['m.nick'] = ['like', '%'.$q.'%'];
        }
        if($is_apply) {
            $map['r.is_apply'] = ['like', '%'.$is_apply.'%'];
        }
        $map['r.is_del'] = 0;
        $map['r.status'] = 1;
        $data_list = Db::name('facescore_content r')->join('admin_member m','m.id = r.uid')->field('r.*')->where($map)->order('r.shunxu asc,r.create_time desc')->paginate(10, false, ['query' => input('get.')]);
        $pages = $data_list->render();
        $this->assign('data_list', $data_list);
        $this->assign('pages', $pages);
        $this->assign('is_apply', $is_apply);
        return $this->fetch();
    }

    public function shunxu($val = '',$ids = ''){
        Db::name('facescore_content')->where(['id' => $ids])->update(['shunxu' => $val]);
        return json(['msg'=>'顺序设置成功']);
    }

    /*
    * 用户流水记录
    */
    public function flow($q = '',$content_id = ''){
        $map = [];
        if ($q) {
            $map['m.nick'] = ['like', '%'.$q.'%'];
        }
        $data_list = Db::name('facescore_flow f')->join('admin_member m','m.id = f.uid','left')->field('f.*,m.nick')->where($map)->order('f.time desc')->paginate(10, false, ['query' => input('get.')]);
        $pages = $data_list->render();
        $this->assign('data_list', $data_list);
        $this->assign('pages', $pages);
        return $this->fetch();
    }

}